#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using ll  = long long;

const ll max_n = 100000+5;
ll n, m, ans[max_n], in_degree[max_n];
std::vector<ll> next[max_n];
std::queue<ll> q;

int main(){
    std::cin>>n>>m;
    for(ll i{1};i<=n;i++)ans[i]=1;
    for(ll i{1};i<=m;i++){
        ll a,b;
        std::cin>>a>>b;
        next[a].push_back(b);
        in_degree[b]++;
    }
    for(ll i{1};i<=n;i++){
        if(in_degree[i]==0){
            q.push(i);
        }
    }
    while(!q.empty()){
        const ll front = q.front();
        q.pop();
        for(const ll i:next[front]){
            ans[i] = std::max(ans[i],ans[front]+1);
            --in_degree[i];
            if(in_degree[i]==0){
                q.push(i);
            }
        }
    }
    for(ll i{1};i<=n;i++){
        std::cout<<ans[i]<<'\n';
    }
}